
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>使用矩阵键盘4个按键控制流水灯模式 · WQ GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-intopic-toc/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-callouts/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-page-footer-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../styles/styles.css">
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="keyboards_led.html" />
    
    
    <link rel="prev" href="keyboards.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../lab0/introduction.html">
            
                <a href="../lab0/introduction.html">
            
                    
                    LAB0: 工欲善其事 必先利其器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../lab0/FPGAintro.html">
            
                <a href="../lab0/FPGAintro.html">
            
                    
                    FPGA 简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../lab0/whyFPGA.html">
            
                <a href="../lab0/whyFPGA.html">
            
                    
                    为什么是 FPGA？
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../lab0/design_method.html">
            
                <a href="../lab0/design_method.html">
            
                    
                    设计方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../lab0/board_intro.html">
            
                <a href="../lab0/board_intro.html">
            
                    
                    平台介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../lab0/intro_tools.html">
            
                <a href="../lab0/intro_tools.html">
            
                    
                    软硬件关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../lab0/keil.html">
            
                <a href="../lab0/keil.html">
            
                    
                    Keil
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../lab0/vivado.html">
            
                <a href="../lab0/vivado.html">
            
                    
                    Vivado
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../lab0/modelsim.html">
            
                <a href="../lab0/modelsim.html">
            
                    
                    Modelsim
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../lab1/introduction.html">
            
                <a href="../lab1/introduction.html">
            
                    
                    LAB1: "施法"让 CPU 动起来
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../lab1/sec_1.html">
            
                <a href="../lab1/sec_1.html">
            
                    
                    ARM 汇编回顾
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../lab1/sec_2.html">
            
                <a href="../lab1/sec_2.html">
            
                    
                    搭建 Keil 环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../lab1/sec_3.html">
            
                <a href="../lab1/sec_3.html">
            
                    
                    运行吧, 第一个汇编程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../lab1/sec_5.html">
            
                <a href="../lab1/sec_5.html">
            
                    
                    栈 - 函数调用的指挥官
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../lab1/sec_6.html">
            
                <a href="../lab1/sec_6.html">
            
                    
                    自己动手, 理解函数调用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../lab2/introduction.html">
            
                <a href="../lab2/introduction.html">
            
                    
                    LAB2: "点石成金" - 实现你的首个 SoC
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../lab2/sec_1.html">
            
                <a href="../lab2/sec_1.html">
            
                    
                    硬件部分说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../lab2/sec_2.html">
            
                <a href="../lab2/sec_2.html">
            
                    
                    搭建 Keil 工程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../lab2/sec_3.html">
            
                <a href="../lab2/sec_3.html">
            
                    
                    Modelsim 仿真
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../lab2/sec_4.html">
            
                <a href="../lab2/sec_4.html">
            
                    
                    下载比特流到 FPGA
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../lab2/sec_5.html">
            
                <a href="../lab2/sec_5.html">
            
                    
                    将硬件固化到开发板
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../lab2/sec_6.html">
            
                <a href="../lab2/sec_6.html">
            
                    
                    使用 Keil 调试
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../lab3/introduction.html">
            
                <a href="../lab3/introduction.html">
            
                    
                    LAB3: "灯, 等灯, 等灯"-流水灯的几种点法
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../lab3/data_storage.html">
            
                <a href="../lab3/data_storage.html">
            
                    
                    数据存储器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../lab3/GPIO.html">
            
                <a href="../lab3/GPIO.html">
            
                    
                    GPIO外设实现流水灯
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../lab3/WaterLight.html">
            
                <a href="../lab3/WaterLight.html">
            
                    
                    硬件流水灯
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="introduction.html">
            
                <a href="introduction.html">
            
                    
                    LAB4: 如何召唤"沉睡的软件"
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="keyboards.html">
            
                <a href="keyboards.html">
            
                    
                    矩阵键盘原理
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.6.2" data-path="keyboards_waterlight.html">
            
                <a href="keyboards_waterlight.html">
            
                    
                    使用矩阵键盘4个按键控制流水灯模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="keyboards_led.html">
            
                <a href="keyboards_led.html">
            
                    
                    使用矩阵键盘控制数码管显示
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../verilog/introduction.html">
            
                <a href="../verilog/introduction.html">
            
                    
                    附录
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../verilog/grammar.html">
            
                <a href="../verilog/grammar.html">
            
                    
                    Verilog基本语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../verilog/enable_signal.html">
            
                <a href="../verilog/enable_signal.html">
            
                    
                    使能信号
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../verilog/decoder.html">
            
                <a href="../verilog/decoder.html">
            
                    
                    总线译码器
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../faq/introduction.html">
            
                <a href="../faq/introduction.html">
            
                    
                    常见问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../add_notice.html">
            
                <a href="../add_notice.html">
            
                    
                    补充通知
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../about/introduction.html">
            
                <a href="../about/introduction.html">
            
                    
                    About
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >使用矩阵键盘4个按键控制流水灯模式</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x4F7F;&#x7528;&#x77E9;&#x9635;&#x952E;&#x76D8;4&#x4E2A;&#x6309;&#x952E;&#x63A7;&#x5236;&#x6D41;&#x6C34;&#x706F;&#x6A21;&#x5F0F;">&#x4F7F;&#x7528;&#x77E9;&#x9635;&#x952E;&#x76D8;4&#x4E2A;&#x6309;&#x952E;&#x63A7;&#x5236;&#x6D41;&#x6C34;&#x706F;&#x6A21;&#x5F0F;</h2>
<!-- -->
<div class="panel panel-success"><div class="panel-heading"><h5 class="panel-title" id="&#x4F7F;&#x7528;&#x77E9;&#x9635;&#x952E;&#x76D8;4&#x4E2A;&#x6309;&#x952E;&#x63A7;&#x5236;&#x6D41;&#x6C34;&#x706F;&#x6A21;&#x5F0F;"><i class="fa fa-flag"></i> &#x4F7F;&#x7528;&#x77E9;&#x9635;&#x952E;&#x76D8;4&#x4E2A;&#x6309;&#x952E;&#x63A7;&#x5236;&#x6D41;&#x6C34;&#x706F;&#x6A21;&#x5F0F;</h5></div><div class="panel-body"><ul>
<li>&#x5728;&#x8FD9;&#x6B21;&#x5B9E;&#x9A8C;&#x4E2D;, &#x6211;&#x4EEC;&#x9700;&#x8981;&#x628A; 4 &#x4E2A;&#x6309;&#x952E;&#x5206;&#x522B;&#x5206;&#x914D;&#x5230; Cortex-M0 &#x7684; IRQ0-IRQ3 &#x56DB;&#x4E2A;&#x4E2D;&#x65AD;&#x4E0A;, &#x6309;&#x952E;&#x7684;&#x7535;&#x5E73;&#x53D8;&#x5316;&#x5C31;&#x4F1A;&#x89E6;&#x53D1; Cortex-M0 &#x5BF9;&#x5E94;&#x7684;&#x4E2D;&#x65AD;. &#x7136;&#x540E;&#x5904;&#x7406;&#x5668;&#x5728;&#x4E2D;&#x65AD;&#x670D;&#x52A1;&#x7A0B;&#x5E8F;&#x4E2D;, &#x63A7;&#x5236;&#x786C;&#x4EF6;&#x6D41;&#x6C34;&#x706F;&#x4EE5;&#x4E0D;&#x540C;&#x6A21;&#x5F0F;&#x8FD0;&#x884C;. </li>
<li>&#x672C;&#x5B9E;&#x9A8C;&#x5B9E;&#x73B0;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x7684; SoC.</li>
</ul></div></div>
<p><div align="center"><img src="../img/lab4/03.png" alt="01" style="zoom:100%;"></div></p>
<center style="color:#000000;font-size:10pt;">&#x672C;&#x6B21;&#x5B9E;&#x9A8C;&#x7684;SoC</center>

<h3 id="&#x4E2D;&#x65AD;&#x7684;&#x76F8;&#x5173;&#x77E5;&#x8BC6;">&#x4E2D;&#x65AD;&#x7684;&#x76F8;&#x5173;&#x77E5;&#x8BC6;</h3>
<p>&#x4E2D;&#x65AD;&#x662F;&#x6307;&#x8BA1;&#x7B97;&#x673A;&#x8FD0;&#x884C;&#x8FC7;&#x7A0B;&#x4E2D;, &#x51FA;&#x73B0;&#x67D0;&#x4E9B;&#x610F;&#x5916;&#x60C5;&#x51B5;&#x9700;&#x8981;&#x4E3B;&#x673A;&#x5E72;&#x9884;&#x65F6;, &#x673A;&#x5668;&#x80FD;&#x81EA;&#x52A8;&#x505C;&#x6B62;&#x6B63;&#x5728;&#x8FD0;&#x884C;&#x7684;&#x7A0B;&#x5E8F;&#x5E76;&#x8F6C;&#x5165;&#x5904;&#x7406;&#x65B0;&#x60C5;&#x51B5;&#x7684;&#x7A0B;&#x5E8F;, &#x5904;&#x7406;&#x5B8C;&#x6BD5;&#x540E;&#x53C8;&#x8FD4;&#x56DE;&#x539F;&#x88AB;&#x6682;&#x505C;&#x7684;&#x7A0B;&#x5E8F;&#x7EE7;&#x7EED;&#x8FD0;&#x884C;.</p>
<p>&#x6839;&#x636E; ARMv6-M &#x67B6;&#x6784;&#x53C2;&#x8003;&#x624B;&#x518C;&#x4EE5;&#x53CA; Cortex-M0 &#x7528;&#x6237;&#x624B;&#x518C;, CPU &#x4E2D;&#x65AD;&#x5904;&#x7406;&#x8FC7;&#x7A0B;&#x5982;&#x4E0B;:</p>
<ul>
<li>CPU &#x63A5;&#x6536;&#x5230;&#x4E2D;&#x65AD;&#x4FE1;&#x53F7;(IRQ&#x3001;NMI&#x3001;Systick&#x7B49;&#x7B49;);</li>
<li>&#x5C06; R0,R1,R2,R3,R12,LR,PC,xPSR &#x5BC4;&#x5B58;&#x5668;&#x5165;&#x6808;, &#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;;</li>
<li>&#x6839;&#x636E;&#x4E2D;&#x65AD;&#x4FE1;&#x53F7;&#x67E5;&#x627E;&#x4E2D;&#x65AD;&#x5411;&#x91CF;&#x8868;(&#x5BF9;&#x5E94;&#x6C47;&#x7F16;&#x542F;&#x52A8;&#x4EE3;&#x7801;&#x4E2D;&#x7684;__Vector&#x6BB5;), &#x8DF3;&#x8F6C;&#x81F3;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x51FD;&#x6570;;</li>
<li>&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x51FD;&#x6570;&#x6267;&#x884C;&#x5B8C;&#x6210;&#x540E;, &#x5229;&#x7528;&#x94FE;&#x63A5;&#x5BC4;&#x5B58;&#x5668;&#x8FD4;&#x56DE;, &#x5BC4;&#x5B58;&#x5668;&#x51FA;&#x6808;, PC &#x8DF3;&#x8F6C;.</li>
</ul>
<p><div align="center"><img src="../img/lab4/01.png" alt="01" style="zoom:100%;"></div></p>
<center style="color:#000000;font-size:10pt;">&#x5BC4;&#x5B58;&#x5668;&#x5165;&#x6808;</center>

<p>&#x5F02;&#x5E38;&#x4E2D;&#x65AD;&#x5411;&#x91CF;&#x8868;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;.</p>
<p><div align="center"><img src="../img/lab4/02.png" alt="01" style="zoom:100%;"></div></p>
<center style="color:#000000;font-size:10pt;">&#x5F02;&#x5E38;&#x4E2D;&#x65AD;&#x5411;&#x91CF;&#x8868;</center>

<!-- -->
<div class="panel panel-info"><div class="panel-heading"><h5 class="panel-title" id="&#x6362;&#x4E2A;&#x89D2;&#x5EA6;&#x770B;&#x4E2D;&#x65AD;"><i class="fa fa-edit"></i> &#x6362;&#x4E2A;&#x89D2;&#x5EA6;&#x770B;&#x4E2D;&#x65AD;</h5></div><div class="panel-body"><p>&#x4E2D;&#x65AD;&#x7684;&#x672C;&#x8D28;&#x662F;&#x5904;&#x7406;&#x5668;&#x5BF9;&#x5916;&#x5F00;&#x653E;&#x7684;&#x5B9E;&#x65F6;&#x53D7;&#x63A7;&#x63A5;&#x53E3;. &#x53EF;&#x4EE5;&#x8BBE;&#x60F3;&#x4E00;&#x4E2A;&#x6CA1;&#x6709;&#x4E2D;&#x65AD;&#x7684;&#x8BA1;&#x7B97;&#x673A;&#x4F53;&#x7CFB;: &#x5F97;&#x77E5;&#x67D0;&#x4E2A;&#x65F6;&#x523B; CPU &#x548C;&#x5185;&#x5B58;&#x7684;&#x5168;&#x90E8;&#x6570;&#x636E;&#x72B6;&#x6001;, &#x5C31;&#x53EF;&#x4EE5;&#x63A8;&#x884D;&#x51FA;&#x672A;&#x6765;&#x7684;&#x5168;&#x90E8;&#x8FC7;&#x7A0B;. &#x8FD9;&#x6837;&#x7684;&#x8BA1;&#x7B97;&#x673A;&#x65E0;&#x6CD5;&#x4EA4;&#x4E92;, &#x53EA;&#x662F;&#x4E2A;&#x52A0;&#x901F;&#x5668;. &#x6DFB;&#x52A0;&#x4E2D;&#x65AD;&#x540E;, &#x8BA1;&#x7B97;&#x673A;&#x6307;&#x5B9A;&#x4E86;&#x4F1A;&#x517C;&#x5BB9;&#x54EA;&#x4E9B;&#x5916;&#x90E8;&#x547D;&#x4EE4;, &#x5E76;&#x8BBE;&#x5B9A;&#x670D;&#x52A1;&#x7A0B;&#x5E8F;, &#x8FD9;&#x79CD;&#x670D;&#x52A1;&#x53EF;&#x80FD;&#x6253;&#x65AD;&#x5F53;&#x524D;&#x4EFB;&#x52A1;. &#x8FD9;&#x4F7F;&#x5F97; CPU &quot;&#x6B63;&#x5728;&#x6267;&#x884C;&#x7684;&#x7A0B;&#x5E8F;&quot; &#x4E0E; &quot;&#x968F;&#x65F6;&#x53EF;&#x80FD;&#x53D1;&#x751F;&#x7684;&#x670D;&#x52A1;&quot; &#x4E8C;&#x8005;&#x5F62;&#x6210;&#x4E86;&#x5F02;&#x6B65;&#x5173;&#x7CFB;, &#x5916;&#x754C;&#x8F93;&#x5165;&#x7684;&#x5F15;&#x5165;&#x4F7F;&#x5F97;&#x8BA1;&#x7B97;&#x673A;&#x7A0B;&#x5E8F;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x4E0E;&#x5916;&#x754C;&#x7684;&#x4EA4;&#x4E92;. &#x7531;&#x4EBA;&#x5B9E;&#x65F6;&#x63A7;&#x5236;&#x7684;&#x4E2D;&#x65AD;&#x8F93;&#x5165;, &#x662F;&#x65E0;&#x6CD5;&#x9884;&#x6D4B;&#x7684;. &#x518D;&#x5C06;&#x4E2D;&#x65AD;&#x54CD;&#x5E94;&#x89C4;&#x8303;&#x5316;, &#x8FDB;&#x800C;&#x63A8;&#x5E7F;&#x5F00;, &#x666E;&#x901A;&#x4EBA;&#x7FA4;&#x4E5F;&#x5C31;&#x53EF;&#x4EE5;&#x63A7;&#x5236;&#x8BA1;&#x7B97;&#x673A;, &#x53D1;&#x6325;&#x6BCF;&#x4E2A;&#x4EBA;&#x7684;&#x521B;&#x9020;&#x529B;.</p></div></div>
<h3 id="&#x786C;&#x4EF6;&#x6A21;&#x5757;&#x4EE3;&#x7801;">&#x786C;&#x4EF6;&#x6A21;&#x5757;&#x4EE3;&#x7801;</h3>
<p>&#x7B2C;&#x4E00;&#x6B65;, &#x5C06;&#x6309;&#x952E;&#x6A21;&#x5757;&#x8F93;&#x51FA;&#x7684;&#x4FE1;&#x53F7;&#x63A5;&#x5230; Cortex-M0 &#x7CFB;&#x7EDF;&#x7684; IRQ &#x4FE1;&#x53F7;&#x4E0A;, &#x56E0;&#x6B64;&#x5728; CortexM0_SoC.v &#x6587;&#x4EF6;&#x505A;&#x5982;&#x4E0B;&#x4FEE;&#x6539;.</p>
<pre><code class="lang-verilog"><span class="hljs-comment">/*Connect the IRQ with keyboard*/</span>
<span class="hljs-keyword">assign</span> IRQ = <span class="hljs-number">32</span>&apos;b0;
<span class="hljs-comment">/***************************/</span>
</code></pre>
<p>&#x6539;&#x4E3A;:</p>
<pre><code class="lang-verilog"><span class="hljs-comment">/*Connect the IRQ with keyboard*/</span>
<span class="hljs-keyword">assign</span> IRQ = {<span class="hljs-number">28</span>&apos;b0,key_interrupt};
<span class="hljs-comment">/***************************/</span>
</code></pre>
<p>&#x63A5;&#x4E0B;&#x6765;&#xFF0C;&#x6211;&#x4EEC;&#x5728; WaterLight &#x5B9E;&#x9A8C;&#x7684; vivado &#x7EA6;&#x675F;&#x6587;&#x4EF6;&#x7684;&#x57FA;&#x7840;&#x4E0A;&#x6DFB;&#x52A0;&#x6309;&#x952E;&#x7AEF;&#x53E3;&#x7684;&#x7EA6;&#x675F;.</p>
<h3 id="&#x542F;&#x52A8;&#x4EE3;&#x7801;&#x4E0E;-c-&#x7F16;&#x7A0B;">&#x542F;&#x52A8;&#x4EE3;&#x7801;&#x4E0E; C &#x7F16;&#x7A0B;</h3>
<p>&#x6211;&#x4EEC;&#x9700;&#x8981;&#x6839;&#x636E; CMSIS &#x63D0;&#x4F9B;&#x7684;&#x542F;&#x52A8;&#x4EE3;&#x7801;&#x91CD;&#x65B0;&#x5B8C;&#x6210;&#x81EA;&#x5DF1;&#x7684;&#x542F;&#x52A8;&#x4EE3;&#x7801;, &#x5177;&#x4F53;&#x4EE3;&#x7801;&#x89C1; &quot;/Task4/key_waterlight/keil/startup_CMSDK_CM0.s&quot;.</p>
<p>&#x4E0E;&#x4E4B;&#x524D;&#x7684;&#x6C47;&#x7F16;&#x4EE3;&#x7801;&#x4E0D;&#x540C;&#x7684;&#x662F;, &#x6211;&#x4EEC;&#x5728;&#x590D;&#x4F4D;&#x5904;&#x7406;&#x51FD;&#x6570;&#x5185;&#x8C03;&#x7528;&#x4E86;_main&#x51FD;&#x6570;, &#x6B64;&#x51FD;&#x6570;&#x7684;&#x4F5C;&#x7528;&#x662F;&#x5C06;&#x5806;&#x6808;&#x521D;&#x59CB;&#x5316;&#x540E;&#x8DF3;&#x8F6C;&#x81F3; C &#x8BED;&#x8A00;&#x4E2D;&#x7684; main &#x51FD;&#x6570;, &#x800C;&#x6700;&#x540E;&#x4E00;&#x6BB5;   __user_initial_stackheap &#x5219;&#x662F;&#x521D;&#x59CB;&#x5316;&#x5806;&#x6808;&#x8FC7;&#x7A0B;&#x7684;&#x4E00;&#x90E8;&#x5206;. &#x521D;&#x59CB;&#x5316;&#x5806;&#x6808;&#x7684;&#x5177;&#x4F53;&#x8FC7;&#x7A0B;&#x7531;&#x7F16;&#x8BD1;&#x5668;&#x63D0;&#x4F9B;, &#x65E0;&#x9700;&#x4EBA;&#x4E3A;&#x6DFB;&#x52A0;. </p>
<p>&#x5728;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x7684;&#x5730;&#x65B9;&#x53EF;&#x4EE5;&#x770B;&#x5230;, &#x5F53;&#x6309;&#x952E;&#x4E2D;&#x65AD;&#x53D1;&#x751F;&#x540E;, CPU &#x4F1A;&#x6839;&#x636E; __Vector&#x4E2D;&#x7684;&#x4E2D;&#x65AD;&#x5730;&#x5740;&#x8DF3;&#x8F6C;&#x5230;&#x6309;&#x952E;&#x4E2D;&#x65AD;&#x5904;&#x7406;&#x51FD;&#x6570;, &#x5728;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x91CC;&#x9762;, &#x9996;&#x5148;&#x4EBA;&#x4E3A;&#x5730;&#x5C06;&#x5BC4;&#x5B58;&#x5668;&#x5165;&#x6808;, &#x7136;&#x540E;&#x8DF3;&#x8F6C;&#x81F3; C &#x8BED;&#x8A00;&#x4E2D;&#x7684; key &#x51FD;&#x6570;, &#x6267;&#x884C;&#x5B8C;&#x6210;&#x540E;&#x5BC4;&#x5B58;&#x5668;&#x51FA;&#x6808;&#x5E76;&#x8FD4;&#x56DE;.</p>
<p>&#x5148;&#x4FEE;&#x6539; __Vector &#x4E2D;&#x65AD;&#x5411;&#x91CF;&#x8868;&#x5982;&#x4E0B;:</p>
<pre><code class="lang-c">__Vectors       DCD     __initial_sp              ; Top of Stack
                DCD     Reset_Handler             ; Reset Handler
                DCD     <span class="hljs-number">0</span>                          ; NMI Handler
                DCD     <span class="hljs-number">0</span>                          ; Hard Fault Handler
                DCD     <span class="hljs-number">0</span>                         ; Reserved
                DCD     <span class="hljs-number">0</span>                         ; Reserved
                DCD     <span class="hljs-number">0</span>                         ; Reserved
                DCD     <span class="hljs-number">0</span>                         ; Reserved
                DCD     <span class="hljs-number">0</span>                         ; Reserved
                DCD     <span class="hljs-number">0</span>                         ; Reserved
                DCD     <span class="hljs-number">0</span>                         ; Reserved
                DCD     <span class="hljs-number">0</span>                          ; SVCall Handler
                DCD     <span class="hljs-number">0</span>                         ; Reserved
                DCD     <span class="hljs-number">0</span>                         ; Reserved
                DCD     <span class="hljs-number">0</span>                          ; PendSV Handler
                DCD     <span class="hljs-number">0</span>                            ; SysTick Handler
                DCD     KEY0_Handler              ; IRQ0 Handler
                DCD     KEY1_Handler              ; IRQ1 Handler
                DCD     KEY2_Handler              ; IRQ2 Handler
                DCD     KEY3_Handler              ; IRQ3 Handler
</code></pre>
<p>&#x6DFB;&#x52A0;&#x4E2D;&#x65AD;&#x670D;&#x52A1;&#x51FD;&#x6570;&#x7684;&#x5165;&#x53E3;, &#x5982;&#x4E0B;:</p>
<pre><code class="lang-c">; add IRQ Handler function here

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
</code></pre>
<p>&#x6539;&#x4E3A;:</p>
<pre><code class="lang-c">KEY0_Handler    PROC
                  EXPORT KEY0_Handler            [WEAK]
                IMPORT KEY0
                PUSH    {R0,R1,R2,LR}
                   BL        KEY0
                POP        {R0,R1,R2,PC}
                   ENDP

KEY1_Handler    PROC
                  EXPORT KEY1_Handler            [WEAK]
                IMPORT KEY1
                PUSH    {R0,R1,R2,LR}
                   BL        KEY1
                POP        {R0,R1,R2,PC}
                   ENDP

KEY2_Handler    PROC
                   EXPORT KEY2_Handler            [WEAK]
                IMPORT KEY2
                PUSH    {R0,R1,R2,LR}
                   BL        KEY2
                POP        {R0,R1,R2,PC}
                   ENDP

KEY3_Handler    PROC
                   EXPORT KEY3_Handler            [WEAK]
                IMPORT KEY3
                PUSH    {R0,R1,R2,LR}
                   BL        KEY3
                POP        {R0,R1,R2,PC}
                   ENDP
</code></pre>
<p>&#x7136;&#x540E;, &#x6211;&#x4EEC;&#x9700;&#x8981;&#x5B9A;&#x4E49;&#x5916;&#x8BBE;&#x7684;&#x5730;&#x5740;, &#x4EE5;&#x53CA;&#x81EA;&#x5DF1;&#x5B9E;&#x73B0;&#x7684;&#x51FD;&#x6570;, &#x53C2;&#x8003; CMSIS &#x7F16;&#x5199;&#x81EA;&#x5DF1;&#x5934;&#x6587;&#x4EF6;. &#x5177;&#x4F53;&#x4EE3;&#x7801;&#x89C1; &#x201C;/Task4/key_waterlight//keil/code_def.h&#x201D;.</p>
<pre><code class="lang-cpp"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;stdint.h&gt;</span></span>
<span class="hljs-comment">//INTERRUPT DEF</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> NVIC_CTRL_ADDR (*(volatile unsigned *)0xe000e100)</span>
<span class="hljs-comment">//WATERLIGHT DEF</span>
<span class="hljs-keyword">typedef</span> <span class="hljs-keyword">struct</span>{
    <span class="hljs-keyword">volatile</span> <span class="hljs-keyword">uint32_t</span> WaterLight_MODE;
    <span class="hljs-keyword">volatile</span> <span class="hljs-keyword">uint32_t</span> WaterLight_SPEED; 
}WaterLightType;
<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> WaterLight_BASE 0x40000000</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> WaterLight ((WaterLightType *)WaterLight_BASE)</span>

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">SetWaterLightMode</span><span class="hljs-params">(<span class="hljs-keyword">int</span> mode)</span></span>;
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">SetWaterLightSpeed</span><span class="hljs-params">(<span class="hljs-keyword">int</span> speed)</span></span>;
</code></pre>
<p>&#x7B2C;&#x4E00;&#x884C; <stdint.h> &#x5934;&#x6587;&#x4EF6;&#x63D0;&#x4F9B;&#x4E86;&#x7ED3;&#x6784;&#x4F53;&#x4EE5;&#x53CA;&#x7ED3;&#x6784;&#x4F53;&#x8FD0;&#x7B97;&#x7B26; &quot;-&gt;&quot; &#x7684;&#x652F;&#x6301;, &#x9AD8;&#x6548;&#x5730;&#x5229;&#x7528;&#x7ED3;&#x6784;&#x4F53;&#x5B9A;&#x4E49;&#x5916;&#x8BBE;&#x5730;&#x5740;, &#x80FD;&#x591F;&#x6709;&#x6548;&#x5730;&#x51CF;&#x5C11;&#x4EE3;&#x7801;&#x91CF;, &#x8282;&#x7EA6;&#x5B58;&#x50A8;&#x7A7A;&#x95F4;.</stdint.h></p>
<p>&#x4E0B;&#x9762;&#x4EE5; WaterLight &#x4E3A;&#x4F8B;&#x8BB2;&#x89E3;&#x7ED3;&#x6784;&#x4F53;&#x4E0E;&#x57FA;&#x5730;&#x5740;&#x7684;&#x4F7F;&#x7528;. &#x9996;&#x5148;&#x6211;&#x4EEC;&#x6839;&#x636E;&#x4E4B;&#x524D; WaterLight &#x786C;&#x4EF6;&#x90E8;&#x5206;&#x8BBE;&#x8BA1;, WaterLight &#x5728;&#x5730;&#x5740;&#x7A7A;&#x95F4;&#x80FD;&#x6709;&#x4E24;&#x4E2A;&#x5BC4;&#x5B58;&#x5668;, &#x5206;&#x522B;&#x4E3A; Waterlight_MODE&#x3001;Waterlight_SPEED, &#x5B83;&#x4EEC;&#x7684;&#x5730;&#x5740;&#x5206;&#x522B;&#x4E3A; 0x40000000&#x3001;0x40000004. &#x4E24;&#x4E2A;&#x5BC4;&#x5B58;&#x5668;&#x5728;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#x4E2D;&#x662F;&#x8FDE;&#x7EED;&#x7684;&#x4E24;&#x4E2A;&#x5B57; (word), &#x56E0;&#x6B64;&#x5728;&#x7ED3;&#x6784;&#x4F53;&#x4E2D;&#x5B9A;&#x4E49;&#x4E24;&#x4E2A;&#x5BC4;&#x5B58;&#x5668;&#x65F6;&#x9700;&#x8981;&#x6309;&#x7167;&#x5B83;&#x4EEC;&#x5730;&#x5740;&#x7684;&#x987A;&#x5E8F;&#x4F9D;&#x6B21;&#x5B9A;&#x4E49;, &#x5E76;&#x4E14;&#x7C7B;&#x578B;&#x4E3A; 32bit &#x7684; uint32_t. &#x4E4B;&#x540E;&#x518D;&#x5B9A;&#x4E49; WaterLight &#x7684;&#x57FA;&#x5730;&#x5740;&#x4E3A; 0x40000000. &#x8FD9;&#x6837;&#x4E00;&#x6765;, &#x5F53;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x7ED3;&#x6784;&#x4F53;&#x4E2D;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x65F6;, &#x5B83;&#x7684;&#x5730;&#x5740;&#x5219;&#x4E3A;&#x57FA;&#x5730;&#x5740; +0; &#x7B2C;&#x4E8C;&#x4E2A;&#x5730;&#x5740;&#x4E3A;&#x57FA;&#x5730;&#x5740; +4; &#x7B2C;&#x4E09;&#x4E2A;&#x5730;&#x5740;&#x4E3A;&#x57FA;&#x5730;&#x5740; +8 &#x4F9D;&#x6B21;&#x7C7B;&#x63A8;. &#x5B8C;&#x5168;&#x7B26;&#x5408;&#x6211;&#x4EEC;&#x5728;&#x786C;&#x4EF6;&#x65F6;&#x5B9A;&#x4E49;&#x7684;&#x5730;&#x5740;.</p>
<p>&#x7136;&#x540E;, &#x6211;&#x4EEC;&#x9700;&#x8981;&#x5B8C;&#x6210;&#x51FD;&#x6570;&#x7684;&#x5B9E;&#x73B0;, &#x5177;&#x4F53;&#x89C1; &quot;/Task4/key_waterlight/keil/code_def.c&quot;.</p>
<pre><code class="lang-c"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-string">&quot;code_def.h&quot;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;string.h&gt;</span></span>

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">SetWaterLightMode</span><span class="hljs-params">(<span class="hljs-keyword">int</span> mode)</span>
</span>{
    WaterLight -&gt; Waterlight_MODE = mode;
}

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">SetWaterLightSpeed</span><span class="hljs-params">(<span class="hljs-keyword">int</span> speed)</span>
</span>{
    WaterLight -&gt; Waterlight_SPEED = speed;
}
</code></pre>
<p>&#x5728;&#x6709;&#x4E86;&#x8FD9;&#x4E9B;&#x51FD;&#x6570;&#x4EE5;&#x540E;, &#x6211;&#x4EEC;&#x6839;&#x636E; startup_CMSDK_CM0.s &#x542F;&#x52A8;&#x6587;&#x4EF6;&#x4E2D;&#x6240;&#x5199;&#x7684;&#x6309;&#x952E;&#x4E2D;&#x65AD;&#x670D;&#x52A1;&#x51FD;&#x6570;&#x7684;&#x540D;&#x79F0;, &#x5728; keyboard.c &#x4E2D;&#x8865;&#x5145;&#x5B8C;&#x6574;&#x5BF9;&#x5E94;&#x7684;&#x4E2D;&#x65AD;&#x670D;&#x52A1;&#x51FD;&#x6570;. &#x6309;&#x952E;&#x4E2D;&#x65AD;&#x670D;&#x52A1;&#x51FD;&#x6570;&#x4E2D;, &#x6BCF;&#x4E2A;&#x6309;&#x952E;&#x90FD;&#x5BF9;&#x5E94;&#x4E00;&#x79CD;&#x6D41;&#x6C34;&#x706F;&#x7684;&#x6A21;&#x5F0F;.</p>
<pre><code class="lang-cpp"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;stdint.h&gt;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-string">&quot;code_def.h&quot;</span></span>

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">KEY0</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span>
</span>{
}

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">KEY1</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span>
</span>{
}

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">KEY2</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span>
</span>{
}

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">KEY3</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span>
</span>{
}
</code></pre>
<p>&#x6539;&#x4E3A;:</p>
<pre><code class="lang-cpp"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;stdint.h&gt;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-string">&quot;code_def.h&quot;</span></span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">KEY0</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span>
</span>{
    SetWaterLightMode(<span class="hljs-number">0</span>);
}

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">KEY1</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span>
</span>{
    SetWaterLightMode(<span class="hljs-number">1</span>);
}

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">KEY2</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span>
</span>{
    SetWaterLightMode(<span class="hljs-number">2</span>);
}

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">KEY3</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span>
</span>{
    SetWaterLightMode(<span class="hljs-number">3</span>);
}
</code></pre>
<p>&#x6700;&#x540E;, &#x7F16;&#x5199;&#x4E3B;&#x6587;&#x4EF6;, &#x5177;&#x4F53;&#x5728; &quot;/Task4/key_waterlight/keil/main.c&quot;. &#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;, &#x5728;&#x4E2D;&#x65AD;&#x5F00;&#x542F;&#x4E4B;&#x524D;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x4F7F;&#x80FD;&#x6240;&#x7528;&#x5230;&#x7684;&#x4E2D;&#x65AD;.</p>
<pre><code class="lang-c"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-string">&quot;code_def.h&quot;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;string.h&gt;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;stdint.h&gt;</span></span>

<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> WaterLight_SPEED_VALUE 0x00c9d2ff</span>

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>
</span>{ 
    <span class="hljs-comment">//interrupt initial</span>
    NVIC_CTRL_ADDR = <span class="hljs-number">0xf</span>;

    <span class="hljs-comment">//WATERLIGHT</span>
    SetWaterLightSpeed(WaterLight_SPEED_VALUE);
    <span class="hljs-keyword">while</span>(<span class="hljs-number">1</span>){    
    }
}
</code></pre>
<!-- -->
<div class="panel panel-success"><div class="panel-heading"><h5 class="panel-title" id="c&#x8BED;&#x8A00;&#x4E2D;-&#x5934;&#x6587;&#x4EF6;--&#x548C;&#x6E90;&#x6587;&#x4EF6;&#x7684;&#x5173;&#x7CFB;"><i class="fa fa-lightbulb-o"></i> C&#x8BED;&#x8A00;&#x4E2D;, &#x5934;&#x6587;&#x4EF6;  &#x548C;&#x6E90;&#x6587;&#x4EF6;&#x7684;&#x5173;&#x7CFB;</h5></div><div class="panel-body"><ul>
<li>&#x5728;&#x5B9E;&#x9645;&#x7684;&#x9879;&#x76EE;&#x4E2D;, &#x53EF;&#x80FD;&#x6709;&#x6210;&#x5343;&#x4E0A;&#x4E07;&#x4E2A;&#x6E90;&#x6587;&#x4EF6;,&#x5E76;&#x4E14;&#x4F1A;&#x6839;&#x636E;&#x4E0D;&#x540C;&#x7684;&#x529F;&#x80FD;&#x6A21;&#x5757;&#x5212;&#x5206;&#x4E0D;&#x540C;&#x7684;&#x6E90;&#x6587;&#x4EF6;, &#x90A3;&#x4E48;&#x968F;&#x4E4B;&#x800C;&#x6765;&#x7684;&#x95EE;&#x9898;&#x662F;, &#x4E0D;&#x540C;&#x6587;&#x4EF6;&#x4E4B;&#x95F4;&#x5982;&#x4F55;&#x5171;&#x4EAB;&#x51FD;&#x6570;&#x548C;&#x5168;&#x5C40;&#x53D8;&#x91CF;? &#x8FD9;&#x91CC;&#x5C31;&#x6709;&#x4E86;&#x5934;&#x6587;&#x4EF6;&#x548C;&#x6E90;&#x6587;&#x4EF6;&#x7684;&#x5212;&#x5206;&#x4E86;.</li>
<li>&#x6211;&#x4EEC;&#x5C06;&#x9700;&#x8981;&#x5171;&#x4EAB;&#x7684;&#x51FD;&#x6570;&#x3001;&#x5916;&#x90E8;&#x53D8;&#x91CF;&#x548C;&#x4E00;&#x4E9B;&#x5B8F;&#x5B9A;&#x4E49;&#x58F0;&#x660E;&#x5728;&#x5934;&#x6587;&#x4EF6;&#x4E2D;, &#x5934;&#x6587;&#x4EF6;&#x4E00;&#x822C;&#x4EE5;h&#x7ED3;&#x5C3E;. &#x5C06;&#x5B9A;&#x4E49; (&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x5B9E;&#x73B0;) &#x5199;&#x5728;&#x6E90;&#x6587;&#x4EF6;&#x4E2D;, &#x6E90;&#x6587;&#x4EF6;&#x4E00;&#x822C;&#x4EE5;c&#x7ED3;&#x5C3E;.</li>
<li>&#x5F53;&#x4E0D;&#x540C;&#x6E90;&#x6587;&#x4EF6;&#x4E4B;&#x95F4;&#x9700;&#x8981;&#x5171;&#x4EAB;&#x51FD;&#x6570;&#x6216;&#x8005;&#x53D8;&#x91CF;, &#x53EF;&#x4EE5;&#x901A;&#x8FC7; #include &#x5305;&#x542B;&#x6307;&#x4EE4;&#x5305;&#x542B;&#x5934;&#x6587;&#x4EF6;&#x5373;&#x53EF; (&#x5F53;&#x7136;, &#x5934;&#x6587;&#x4EF6;&#x4E2D;&#x4E5F;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x5176;&#x4ED6;&#x7684;&#x5934;&#x6587;&#x4EF6;, &#x5373;&#x5934;&#x6587;&#x4EF6;&#x7684;&#x5D4C;&#x5957;).</li>
</ul></div></div>
<!-- -->
<div class="panel panel-info"><div class="panel-heading"><h5 class="panel-title" id="&#x7F16;&#x8BD1;&#x5668;&#x7684;&#x5DE5;&#x4F5C;&#x8FC7;&#x7A0B;"><i class="fa fa-comment"></i> &#x7F16;&#x8BD1;&#x5668;&#x7684;&#x5DE5;&#x4F5C;&#x8FC7;&#x7A0B;</h5></div><div class="panel-body"><ul>
<li>(1) &#x9884;&#x5904;&#x7406;&#x9636;&#x6BB5;</li>
<li>(2) &#x8BCD;&#x6CD5;&#x4E0E;&#x8BED;&#x6CD5;&#x5206;&#x6790;&#x9636;&#x6BB5;</li>
<li>(3) &#x7F16;&#x8BD1;&#x9636;&#x6BB5;, &#x9996;&#x5148;&#x7F16;&#x8BD1;&#x6210;&#x7EAF;&#x6C47;&#x7F16;&#x8BED;&#x53E5;, &#x518D;&#x5C06;&#x4E4B;&#x6C47;&#x7F16;&#x6210;&#x8DDF;CPU&#x76F8;&#x5173;&#x7684;&#x4E8C;&#x8FDB;&#x5236;&#x7801;, &#x751F;&#x6210;&#x5404;&#x4E2A;&#x76EE;&#x6807;&#x6587;&#x4EF6;    (.obj&#x6587;&#x4EF6;)</li>
<li>(4) &#x8FDE;&#x63A5;&#x9636;&#x6BB5;, &#x5C06;&#x5404;&#x4E2A;&#x76EE;&#x6807;&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x5404;&#x6BB5;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x7EDD;&#x5BF9;&#x5730;&#x5740;&#x5B9A;&#x4F4D;, &#x751F;&#x6210;&#x8DDF;&#x7279;&#x5B9A;&#x5E73;&#x53F0;&#x76F8;&#x5173;&#x7684;&#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;, &#x5F53;&#x7136;, &#x6700;&#x540E;&#x8FD8;&#x53EF;&#x4EE5;&#x7528;objcopy&#x751F;&#x6210;&#x7EAF;&#x4E8C;&#x8FDB;&#x5236;&#x7801;, &#x4E5F;&#x5C31;&#x662F;&#x53BB;&#x6389;&#x4E86;&#x6587;&#x4EF6;&#x683C;&#x5F0F;&#x4FE1;&#x606F;.</li>
<li>&#x7F16;&#x8BD1;&#x5668;&#x5728;&#x7F16;&#x8BD1;&#x65F6;&#x662F;&#x4EE5; C &#x6587;&#x4EF6;&#x4E3A;&#x5355;&#x4F4D;&#x8FDB;&#x884C;&#x7684;, &#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x5982;&#x679C;&#x4F60;&#x7684;&#x9879;&#x76EE;&#x4E2D;&#x4E00;&#x4E2A; C &#x6587;&#x4EF6;&#x90FD;&#x6CA1;&#x6709;, &#x90A3;&#x4E48;&#x4F60;&#x7684;&#x9879;&#x76EE;&#x5C06;&#x65E0;&#x6CD5;&#x7F16;&#x8BD1;, &#x8FDE;&#x63A5;&#x5668;&#x662F;&#x4EE5;&#x76EE;&#x6807;&#x6587;&#x4EF6;&#x4E3A;&#x5355;&#x4F4D;, &#x5B83;&#x5C06;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x76EE;&#x6807;&#x6587;&#x4EF6;&#x8FDB;&#x884C;&#x51FD;&#x6570;&#x4E0E;&#x53D8;&#x91CF;&#x7684;&#x91CD;&#x5B9A;&#x4F4D;, &#x751F;&#x6210;&#x6700;&#x7EC8;&#x7684;&#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;. &#x800C;&#x8FD9;&#x4E9B; C &#x6587;&#x4EF6;&#x4E2D;&#x53C8;&#x9700;&#x8981;&#x4E00;&#x4E2A; main &#x51FD;&#x6570;&#x4F5C;&#x4E3A;&#x53EF;&#x6267;&#x884C;&#x7A0B;&#x5E8F;&#x7684;&#x5165;&#x53E3;.</li>
</ul></div></div>
<h3 id="&#x8C03;&#x8BD5;&#x4E0E;&#x8FD0;&#x884C;">&#x8C03;&#x8BD5;&#x4E0E;&#x8FD0;&#x884C;</h3>
<p>&#x6253;&#x5F00; Keil &#x5DE5;&#x7A0B;&#x5C06;&#x7F16;&#x5199;&#x597D;&#x7684;&#x6587;&#x4EF6;&#x6DFB;&#x52A0;&#x81F3;&#x5DE5;&#x7A0B;&#x4E2D;, &#x5E76;&#x5728;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x7684;&#x8BBE;&#x7F6E;&#x4E2D;&#x53D6;&#x6D88;&#x52FE;&#x9009; &quot;Don&#x2019;t Search Standard Libraries&quot;, &#x7136;&#x540E;&#x7F16;&#x8BD1;.</p>
<p><div align="center"><img src="../img/lab4/06.png" alt="01" style="zoom:100%;"></div></p>
<center style="color:#000000;font-size:10pt;">&#x53D6;&#x6D88;&#x52FE;&#x9009;</center>

<p>&#x5728;&#x8F6F;&#x4EF6;&#x7F16;&#x8BD1;&#x901A;&#x8FC7;&#x4E4B;&#x540E;, &#x6211;&#x4EEC;&#x4F7F;&#x7528; modelsim &#x8FDB;&#x884C;&#x4EFF;&#x771F;, &#x6211;&#x4EEC;&#x5728; testbench &#x6587;&#x4EF6;&#x4E2D;&#x6DFB;&#x52A0;&#x4E86;&#x4E00;&#x4E2A;&#x6309;&#x952E;&#x4FE1;&#x53F7;&#x7528;&#x4E8E;&#x89E6;&#x53D1;&#x5904;&#x7406;&#x5668;&#x7684;&#x4E2D;&#x65AD;, &#x5728;&#x89E6;&#x53D1;&#x4E2D;&#x65AD;&#x540E;, &#x6211;&#x4EEC;&#x80FD;&#x591F;&#x89C2;&#x5BDF;&#x5904;&#x7406;&#x5668;&#x5185;&#x90E8;&#x7684;&#x53D8;&#x5316;. &#x5728; object &#x754C;&#x9762;, &#x6211;&#x4EEC;&#x9009;&#x62E9;&#x6DFB;&#x52A0; clk,col &#x6309;&#x952E;&#x8F93;&#x5165;&#x7AEF;&#x53E3;, &#x4EE5;&#x53CA;&#x5904;&#x7406;&#x5668;&#x5185;&#x6838;&#x7684; IPSR &#x4E2D;&#x65AD;&#x7A0B;&#x5E8F;&#x72B6;&#x6001;&#x5BC4;&#x5B58;&#x5668;&#x548C; PC &#x5BC4;&#x5B58;&#x5668; vis_ipsr_o. &#x53EF;&#x4EE5;&#x770B;&#x5230;&#x5728;&#x6309;&#x952E;&#x8F93;&#x5165;&#x4FDD;&#x6301;&#x4E00;&#x6BB5;&#x65F6;&#x5019;&#x6709;&#x6548;&#x540E;, IPSR &#x7684;&#x503C;&#x5C31;&#x4F1A;&#x53D8;&#x4E3A; 16, &#x6839;&#x636E;&#x7B2C;&#x4E09;&#x7AE0;&#x6240;&#x8FF0;, IPSR &#x4E3A;&#x8BB0;&#x5F55;&#x5F02;&#x5E38;&#x6807;&#x53F7;&#x7684;&#x5BC4;&#x5B58;&#x5668;. &#x6B64;&#x65F6; IPSR &#x4E3A; 16, &#x67E5;&#x627E;&#x4E2D;&#x65AD;&#x5411;&#x91CF;&#x8868;&#x53EF;&#x77E5;, &#x6B64;&#x65F6;&#x5904;&#x7406;&#x5668;&#x63A5;&#x6536;&#x5230;&#x4E86; IRQ0 &#x4E2D;&#x65AD;.</p>
<p>&#x5728; modelsim &#x4EFF;&#x771F;&#x901A;&#x8FC7;&#x4E4B;&#x540E;, &#x6211;&#x4EEC;&#x5C06;&#x76F8;&#x5173;&#x7684;&#x6587;&#x4EF6;&#x6DFB;&#x52A0;&#x5230; vivado &#x5DE5;&#x7A0B;&#x4E2D;, &#x6700;&#x540E;&#x5C06; vivado &#x751F;&#x6210;&#x7684; bit &#x6D41;&#x6587;&#x4EF6;&#x4E0B;&#x8F7D;&#x5230; FPGA &#x5F00;&#x53D1;&#x677F;&#x4E0A;. &#x6211;&#x4EEC;&#x5C31;&#x80FD;&#x591F;&#x901A;&#x8FC7;&#x6309;&#x952E;&#x63A7;&#x5236;&#x786C;&#x4EF6;&#x6D41;&#x6C34;&#x706F;&#x7684;&#x6A21;&#x5F0F;.</p>
<p>&#x81F3;&#x6B64;, &#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x77E9;&#x9635;&#x952E;&#x76D8;&#x4E2D;&#x7684; 4 &#x4E2A;&#x6309;&#x952E;, &#x901A;&#x8FC7;&#x4E2D;&#x65AD;&#x54CD;&#x5E94;&#x7684;&#x65B9;&#x6CD5;&#x5B9E;&#x73B0;&#x4E86;&#x5BF9;&#x6D41;&#x6C34;&#x706F;&#x5916;&#x8BBE;&#x7684;&#x63A7;&#x5236;. &#x7136;&#x800C;, &#x5BF9;&#x4E8E;&#x4E00;&#x4E9B;&#x590D;&#x6742;&#x7684;&#x5E94;&#x7528;&#x573A;&#x666F;, &#x53EF;&#x80FD;&#x9700;&#x8981;&#x7528;&#x5230;&#x66F4;&#x591A;&#x6309;&#x952E;, &#x5982;&#x679C;&#x4ECD;&#x7136;&#x91C7;&#x7528;&#x8FD9;&#x79CD;&#x4E00;&#x4E2A;&#x6309;&#x952E;&#x5BF9;&#x5E94;&#x4E00;&#x4E2A;&#x4E2D;&#x65AD;&#x7684;&#x65B9;&#x5F0F;&#x5C06;&#x5E26;&#x6765;&#x5F88;&#x5927;&#x7684;&#x5F00;&#x9500; (&#x6BD4;&#x5982;&#x5360;&#x7528;&#x8FC7;&#x591A; CPU &#x4E2D;&#x65AD;&#x7AEF;&#x53E3;&#x5BFC;&#x81F4;&#x6DFB;&#x52A0;&#x65B0;&#x529F;&#x80FD;&#x65F6;&#x53EF;&#x7528;&#x4E2D;&#x65AD;&#x7AEF;&#x53E3;&#x4E0D;&#x8DB3;). &#x56E0;&#x6B64;, &#x672C;&#x5B9E;&#x9A8C;&#x4ECB;&#x7ECD;&#x53E6;&#x5916;&#x4E00;&#x79CD;&#x65B9;&#x6CD5;, &#x5C06;&#x77E9;&#x9635;&#x952E;&#x76D8;&#x5168;&#x90E8;&#x6309;&#x952E;&#x5BF9;&#x5E94; CPU &#x4E0A;&#x4E00;&#x4E2A;&#x4E2D;&#x65AD;&#x7AEF;&#x53E3;, CPU &#x5728;&#x4E2D;&#x65AD;&#x54CD;&#x5E94;&#x65F6;&#x901A;&#x8FC7;&#x603B;&#x7EBF;&#x8BFB;&#x53D6;&#x6309;&#x952E;&#x4FE1;&#x606F;, &#x8FDB;&#x884C;&#x76F8;&#x5E94;&#x7684;&#x64CD;&#x4F5C;.</p>
<footer class="page-footer-ex"> <span class="page-footer-ex-copyright"> By UESTC Intelligent Chip and System Design Lab. &#x91C7;&#x7528;<a href="https://creativecommons.org/licenses/by-nc-sa/3.0/cn/" target="_blank">&#x77E5;&#x8BC6;&#x5171;&#x4EAB; &#x7F72;&#x540D;-&#x975E;&#x5546;&#x4E1A;&#x6027;&#x4F7F;&#x7528;-&#x76F8;&#x540C;&#x65B9;&#x5F0F;&#x5171;&#x4EAB; 3.0 &#x4E2D;&#x56FD;&#x5927;&#x9646; &#x8BB8;&#x53EF;&#x534F;&#x8BAE;</a>&#x53D1;&#x5E03; </span> &#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0; <span class="page-footer-ex-footer-update"> &#x6B64;&#x9875;&#x9762;&#x4FEE;&#x8BA2;&#x4E8E; 2022-04-29 21:55:31 </span> </footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="keyboards.html" class="navigation navigation-prev " aria-label="Previous page: 矩阵键盘原理">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="keyboards_led.html" class="navigation navigation-next " aria-label="Next page: 使用矩阵键盘控制数码管显示">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"使用矩阵键盘4个按键控制流水灯模式","level":"1.6.2","depth":2,"next":{"title":"使用矩阵键盘控制数码管显示","level":"1.6.3","depth":2,"path":"lab4/keyboards_led.md","ref":"lab4/keyboards_led.md","articles":[]},"previous":{"title":"矩阵键盘原理","level":"1.6.1","depth":2,"path":"lab4/keyboards.md","ref":"lab4/keyboards.md","articles":[]},"dir":"ltr"},"config":{"plugins":["intopic-toc","callouts","page-footer-ex","-livereload","theme-comscore","-sharing"],"styles":{"website":"styles/styles.css"},"pluginsConfig":{"callouts":{"important":{"alert":"danger","picto":"fa-bullhorn"},"danger":{"alert":"danger","picto":"fa-exclamation-circle"},"question":{"alert":"info","picto":"fa-question-circle"},"hint":{"alert":"success","picto":"fa-lightbulb-o"},"showTypeInHeader":false,"must":{"alert":"warning","picto":"fa-edit"},"flag":{"alert":"success","picto":"fa-flag"},"info":{"alert":"info","picto":"fa-info-circle"},"note":{"alert":"info","picto":"fa-edit"},"fread":{"alert":"info","picto":"fa-comment"}},"intopic-toc":{"isCollapsed":true,"isScrollspyActive":true,"label":"导航","maxDepth":6,"mode":"nested","selector":".markdown-section h1, .markdown-section h2, .markdown-section h3, .markdown-section h4","visible":true},"page-footer-ex":{"copyright":"By UESTC Intelligent Chip and System Design Lab. 采用[知识共享 署名-非商业性使用-相同方式共享 3.0 中国大陆 许可协议](https://creativecommons.org/licenses/by-nc-sa/3.0/cn/)发布","markdown":true,"update_format":"YYYY-MM-DD HH:mm:ss","update_label":"此页面修订于"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"WQ GitBook","gitbook":"*"},"file":{"path":"lab4/keyboards_waterlight.md","mtime":"2022-04-29T13:55:31.047Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-03-16T07:13:54.762Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-intopic-toc/anchor.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-intopic-toc/gumshoe.polyfills.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-intopic-toc/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

